﻿// Sheego.Service.X400
// Copyright(C) 2015 Schwab Versand GmbH
//
// This source file is subject to the Microsoft Public License(Ms-PL).
// http://www.opensource.org/licenses/ms-pl.html
// All other rights reserved.
using Sheego.Service.X400.Job.Shared;
using Sheego.Service.X400.Job.Shared.BO;
using Sheego.Service.X400.Job.Shared.Locator;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sheego.Service.X400.Job.Impl.BO
{
    class ConfigurationAdapter : IJobConfiguration
    {

        private string ConfigFile = null;
        private IXmlWrapper _configFileWrapper = null;
        private IXmlWrapper ConfigFileWrapper
        {
            get
            {
                if (_configFileWrapper == null)
                {
                    _configFileWrapper = JobLocator.GetXmlWrapper(ConfigFile, "ns", "http://sheego.de/Sheego.Service.X400/Config");
                    _configFileWrapper.Update();
                }
                return _configFileWrapper;
            }
        }

        public ConfigurationAdapter()
        {
            ConfigFile = ConfigurationManager.AppSettings["ConfigFilePath"];
        }


        #region IJobConfiguration Members


        public IRange Hour
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<IRange>("/ns:Config/ns:Hour");
            }
        }

        public IRange Minute
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<IRange>("/ns:Config/ns:Minute");
            }
        }

        public string UAFIWorkingPath
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:UAFIWorkingPath");
            }
        }

        public string UAFICommandPath
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:UAFICommandPath");
            }
        }

        public string UAFIConfigPath
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:UAFIConfigPath");
            }
        }

        public string UAFIMailboxPassword
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:UAFIMailboxPassword");
            }
        }

        public string UAFIMailboxUser
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:UAFIMailboxUser");
            }
        }

        public string SmtpServer
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:SmtpServer");
            }
        }

        public string MailSender
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:MailSender");
            }
        }

        public string ErrorRecipient
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<String>("/ns:Config/ns:ErrorRecipient");
            }
        }

        public bool TestMode
        {
            get
            {
                return ConfigFileWrapper.GetElementByXPath<bool>("/ns:Config/ns:TestMode");
            }
        }

        #endregion
    }
}
